package day9;

import java.util.HashSet;
import java.util.Set;

class ten implements Runnable{
    private Set<Integer> set;
    private Integer num;

    public ten(Set<Integer> set, Integer num) {
        this.set = set;
        this.num = num;
    }

    @Override
    public void run() {
        synchronized (ten.class) {
            multiply(this.set, this.num);
        }
    }

    private int multiply(Set<Integer> set, Integer num) {
        if (num == 1) {
            return 1;
        }else {
            int sum = num * multiply(set, num - 1);
            if (set.contains(num - 1)) System.out.println(sum / num);
            return sum;
        }
    }

}

public class project {

    public static void main(String[] args) {
        Set<Integer> set = new HashSet<>();
        set.add(5);
        set.add(8);
        set.add(10);
        ten t = new ten(set, 19);
        long a = System.currentTimeMillis();
        new Thread(t).start();
        System.out.println(System.currentTimeMillis() - a);
    }
}
